#include "util.h"
#include "minimal_ogl.h"
#include <GL/glfw.h>

boost::function<void (void)> draw_callback;
volatile bool render;

void run(void){
#if 0	
	glfwInit();
	glfwOpenWindow(300,300,0,0,0,0,0,0,GLFW_WINDOW);
	glMatrixMode(GL_MODELVIEW);
	glRotatef(45, 0, 1, 0);
	glRotatef(45,-1, 0,-1);
	glScalef(0.4,0.4,0.4);
	while(render){
		glClear(GL_COLOR_BUFFER_BIT);
		glBegin(GL_LINES);
			glColor3f(1,0,0); glVertex3f(0,0,0); glVertex3f(1,0,0); 
			glColor3f(0,1,0); glVertex3f(0,0,0); glVertex3f(0,1,0); 
			glColor3f(0,0,1); glVertex3f(0,0,0); glVertex3f(0,0,1); 
		glEnd();
		glColor3f(1,1,1);
		draw_callback();
		glfwSwapBuffers();
	}
	glfwTerminate();
#endif
}

void run3D(boost::function<void (void)> fn){
	draw_callback = fn;
	render = true;
	boost::thread(boost::bind(&run));
}


void stop3D(){
	render = false;
}

void draw_point_3D(float x, float y, float z){
	glPointSize(5);
	glBegin(GL_POINTS);
		glVertex3f(x,y,z);
	glEnd();
}

void draw_line_3D(float x1, float y1, float z1, float x2, float y2, float z2){
	glBegin(GL_LINES);
		glVertex3f(x1,y1,z1);
		glVertex3f(x2,y2,z2);
	glEnd();
}